package com.NeuglsWorkStudio.UI.FormElement.Component.Video
{
	import com.NeuglsWorkStudio.UI.Buttons.TTipButton;
	import com.NeuglsWorkStudio.UI.FormElement.Config.TConfig;
	import com.NeuglsWorkStudio.UI.FormElement.Config.TImageConfig;
	import com.NeuglsWorkStudio.UI.FormElement.Config.TVideoPreviewConfig;
	import com.NeuglsWorkStudio.Utility.nConsts;
	
	import flash.display.Bitmap;
	import com.NeuglsWorkStudio.UI.FormElement.Component.TComponent;
	import com.NeuglsWorkStudio.UI.FormElement.Component.TImage;
	
	public class TVideoPreview extends TComponent
	{
		[Embed(source="images/Button/play_normal.png")]
		private var _FPlayOnNormal:Class;

		[Embed(source="images/Button/play_hover.png")]
		private var _FPlayOnHover:Class;
		
		private var _FPlayBtn:TTipButton;
		private var _FPreImage:TImage;
		
		public function TVideoPreview(AConfig:TConfig)
		{
			super(AConfig);
		}
		
		public function VideoPreviewConfig():TVideoPreviewConfig{
			return _FConfig as TVideoPreviewConfig;
		}
		
		override protected function Init():void{
			super.Init();
			if(VideoPreviewConfig().Image||(VideoPreviewConfig().UserURL&&VideoPreviewConfig().ImageURL&&VideoPreviewConfig().ImageURL!='')){
				var ImageConfig:TImageConfig=new TImageConfig();
				ImageConfig.Height=VideoPreviewConfig().Height;
				ImageConfig.Image=VideoPreviewConfig().Image;
				ImageConfig.ImageURL=VideoPreviewConfig().ImageURL;
				ImageConfig.Name=VideoPreviewConfig().Name+'image';
				ImageConfig.ScaleModel=nConsts.bpStretch;
				ImageConfig.UserURL=VideoPreviewConfig().UserURL;
				ImageConfig.Width=VideoPreviewConfig().Width;
				ImageConfig.x=0;
				ImageConfig.y=0;
				_FPreImage=new TImage(ImageConfig);
				this.addChild(_FPreImage);
			}
			
			_FPlayBtn=new TTipButton('',false);
			_FPlayBtn.Image=new _FPlayOnNormal() as Bitmap;
			_FPlayBtn.MouseOverImg=new _FPlayOnHover() as Bitmap;
			_FPlayBtn.ToStopPropagation=true;
			this.addChild(_FPlayBtn);
			_FPlayBtn.OnClick=VideoPreviewConfig().OnPlayBtnClick;
			Paint();
		}
		
		protected function Paint():void{
			if(_FPreImage){
				_FPreImage.x=0;
				_FPreImage.y=0;
			}
			if(!_FPreImage){
				with(this.graphics){
					clear();
					//beginFill(VideoPreviewConfig().BaseColor,0.5);
					beginFill(0x000000,0.5);
					drawRect(0,0,VideoPreviewConfig().Width,VideoPreviewConfig().Height);
					endFill();
				}
			}
			
			this.setChildIndex(_FPlayBtn,this.numChildren-1);
			_FPlayBtn.x=(VideoPreviewConfig().Width)/2;
			_FPlayBtn.y=(VideoPreviewConfig().Height)/2;
		}
	}
}